﻿@model IEnumerable<CoreLims.Models.CoreLims.CommonSiteGroup>

@{
    Layout = null;
}

<div>
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">实验室*</span>
        </div>
        <div class="col-9 pl-0 input-group position-relative">
            <select id="SiteGroup-AddSiteGroup-Select-Site" class="form-control font-rfs border-radius-noleft" style="width:90%" onchange="selectOnchang(this)">
                @foreach (var item in Model)
                {
                    <option value=@item.Site>@item.Site</option>
                }
            </select>
            <div class="col-11 pl-0 input-group position-absolute float-left"><input id="SiteGroup-AddSiteGroup-Input-Site" class="form-control font-rfs border-radius-noleft noRightBorder" style="width:100%" placeholder="可输入新的实验室名称" /></div>
        </div>
    </div><br />
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">工作组*</span>
        </div>
        <div class="col-9 pl-0">
            <input id="SiteGroup-AddSiteGroup-WorkGroup" class="form-control font-rfs border-radius-noleft" placeholder="必填" />
        </div>
    </div><br />
    <div class="input-group">
        <div class="col-3 pr-0">
            <span class="input-group-text font-rfs border-radius-noright noRightBorder">说明</span>
        </div>
        <div class="col-9 pl-0">
            <input id="SiteGroup-AddSiteGroup-Description" class="form-control font-rfs border-radius-noleft" placeholder="可选" />
        </div>
    </div><br />
    <div class="text-right">
        <button id="SiteGroup-AddSiteGroup-confirm" class="btn btn-primary font-rfs">确定</button>
        <button id="SiteGroup-AddSiteGroup-cancel" type="button" class="btn btn-info font-rfs" data-dismiss="modal">取消</button>
    </div>
</div>

<script>
    $("#SiteGroup-AddSiteGroup-Select-Site").prepend(new Option("", ""));
    $("#SiteGroup-AddSiteGroup-Select-Site").val("");

    function selectOnchang(obj) {
        $("#SiteGroup-AddSiteGroup-Input-Site").val($("#SiteGroup-AddSiteGroup-Select-Site").find("option:selected").text());
    };

    $("#SiteGroup-AddSiteGroup-confirm").click(function () {
        if ($("#SiteGroup-AddSiteGroup-Input-Site").val().length == 0) {
            alert("实验室不能为空！");
            $("#SiteGroup-AddSiteGroup-Input-Site").addClass('error-style');
            return false;
        }
        if ($("#SiteGroup-AddSiteGroup-WorkGroup").val().length == 0) {
            alert("工作组不能为空！");
            $("#SiteGroup-AddSiteGroup-WorkGroup").addClass('error-style');
            return false;
        }

        var jsonStr = {};
        jsonStr["ID"] = "";
        jsonStr["Site"] = $("#SiteGroup-AddSiteGroup-Input-Site").val();
        jsonStr["WorkGroup"] = $("#SiteGroup-AddSiteGroup-WorkGroup").val();
        jsonStr["Description"] = $("#SiteGroup-AddSiteGroup-Description").val();

        $.post("postAddSiteGroup", {
            jsonStr: JSON.stringify(jsonStr)
        }, function (data) {
            alert(data);
        });
    });

</script>
